package cn.dengta.webapp.user.form.query;

import java.util.List;

import cn.dengta.common.model.TimeInterval;
import cn.dengta.common.util.Common;
import cn.dengta.common.web.Client;
import cn.dengta.context.model.Member;
import cn.dengta.context.model.WesKit;
import cn.dengta.webapp.base.form.BaseForm;
import cn.dengta.webapp.base.form.QueryBaseForm;
import cn.dengta.webapp.user.entity.ClientInfo.LoginWay;
import cn.dengta.webapp.user.entity.User;
import cn.dengta.webapp.user.model.*;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.StringUtil;
import me.codeplayer.util.X;

@Getter
@Setter
public class UserQuery extends QueryBaseForm<User> {

	public Long id;
	/** 用户ID */
	public Long userId;
	/** 状态 */
	public Integer state;
	/** 昵称 */
	public String nickname;
	/** 实名 */
	public String realName;
	/** 手机号码 */
	public String phone;
	/** 类型 */
	public UserType type;
	/** 邮箱 */
	public String email;
	/** 邀请码 */
	public String inviteCode;
	/** 邀请人ID */
	public Long inviteUserId;
	/** 登录方式 */
	public LoginWay loginWay;
	/** 推荐类型 */
	public RecommendLevel recLevel;
	/** 操作tab：1=获取UserInfo */
	public Integer tab;
	/** 开关配置 */
	public Integer openConfig;
	/** 存在冻结 */
	public Integer existFreeze;
	/** 是否在线 */
	public Integer online;
	/** 推荐标记 */
	public Integer fromRec;
	public Integer fromVisit;
	/** 查询充值 */
	public Integer fromRecharge;
	/** 推广员ID */
	public Long agentId;
	/** 父级推广员ID */
	public Long parentId;
	/** 级别 */
	public Integer agentLevel;
	/** 性别 */
	public Gender gender;
	/** 国家 */
	public String country;
	/** 渠道ID */
	protected Long channelId;
	/** 注册国家 */
	protected String regCountry;
	/** 状态 */
	protected Integer status;
	/** 支付模式：0=vip；1=钻石 */
	public Integer payTab;
	public Long[] channelIds;
	public Client client;
	public Long[] ids;
	public WesKit wesKit;

	public TimeInterval addTimeInterval;

	public void setWesKit(Integer wesKit) {
		this.wesKit = WesKit.of(wesKit);
	}

	public void setLoginWay(Integer loginWay) {
		this.loginWay = LoginWay.of(loginWay);
	}

	public void setGender(Integer gender) {
		this.gender = Gender.of(gender);
	}

	public void setType(Integer type) {
		this.type = UserType.of(type);
	}

	public void setRecLevelTab(Integer recLevelTab) {
		if (recLevelTab == 1) {
			recLevel = RecommendLevel.WHITELIST;
		} else if (recLevelTab == 2) {
			recLevel = RecommendLevel.L12;
		}
	}

	public void setUIds(String uIds) {
		List<String> split = Common.splitAsStringList(uIds);
		if (X.isValid(split)) {
			if (split.size() > 1) {
				ids = split.stream().map(Member::decode).filter(StringUtil::notEmpty).toArray(Long[]::new);
				return;
			}
			id = Member.decode(split.get(0));
		}
	}

}
